package com.rxjava.jsonschema2pojo;

import java.io.File;
import java.io.IOException;
import java.net.URL;

import org.jsonschema2pojo.DefaultGenerationConfig;
import org.jsonschema2pojo.GenerationConfig;
import org.jsonschema2pojo.Jackson2Annotator;
import org.jsonschema2pojo.NoopAnnotator;
import org.jsonschema2pojo.SchemaGenerator;
import org.jsonschema2pojo.SchemaMapper;
import org.jsonschema2pojo.SchemaStore;
import org.jsonschema2pojo.rules.RuleFactory;

import com.sun.codemodel.JCodeModel;

/**
 * json 2 pojo
 * @author linyu
 *https://github.com/joelittlejohn/jsonschema2pojo.git
 */
public class Jsonschema2pojo {
	public static void main(String[] args) throws Exception {
		JCodeModel codeModel = new JCodeModel();

		URL source = new URL("http://www.json-schema.org/address");

		GenerationConfig config = new DefaultGenerationConfig() {
			@Override
			public boolean isGenerateBuilders() { // set config option by
													// overriding method
				return true;
			}
		};

		SchemaMapper mapper = new SchemaMapper(new RuleFactory(config,
				new NoopAnnotator(), new SchemaStore()),
				new SchemaGenerator());
		mapper.generate(codeModel, "ClassName", "com.example", source);
		String relativelyPath=System.getProperty("user.dir"); 
		codeModel.build(new File(relativelyPath));
	}
}
